#include <iostream>
#include <string>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <strings.h>
#include <cstdlib>
// #include "Log.hpp"
using namespace  std;

int main(int argc,char*argv[])
{
    //输入错误提示
    if(argc!=3)
    {
        cout<<"./UdpServe:"<<" serveip serveport"<<endl;
        exit(1);
    }
    //创建套接字
    int sockfd=socket(AF_INET,SOCK_DGRAM,0);
    if(sockfd<0)
    {
        perror("socke failed\n");
        exit(-1);
    }
    cout<<"客户端启动成功\n";
    //客户端不需要进行bind，ip和port是由os自动分配和bind
    struct sockaddr_in tmp;
    bzero(&tmp,sizeof(tmp));
    tmp.sin_family=AF_INET;
    tmp.sin_port=htons(stoi(argv[2]));
    tmp.sin_addr.s_addr= inet_addr(argv[1]);

    while(true)
    {
        cout<<"Please enter@";
        string msg;
        getline(cin,msg);
        sendto(sockfd,msg.c_str(),msg.size(),0,(struct sockaddr*)&tmp,sizeof(tmp));
    }

    return 0;
}